$(function(){
    laydate.render({
        elem: '[name=prodUctDate]'
    });
});
function searchDetailList(index,row) {
    var arr = row.poleInfoList;
    var tb = `<table class='table table-bordered table-striped'>
                        <tr>
                            <th>杆塔编号</th>
                            <th>所属线路名称</th>
                            <th>杆塔状态</th>
                        </tr>`;
    var html = [];
    html.push(tb);

    var num = 0;
    $(arr).each(function () {
        var tr = `<tr>
                               <td style="vertical-align: middle;">${this.poleCode}</td>
                               <td style="vertical-align: middle;">${this.lineName}</td>
                               <td style="vertical-align: middle;">${this.isStart==1?'启用':'停用'}</c:if></td>
                           </tr>`;
        html.push(tr);
    });
    html.push(`</table>`);
    return html.join("");
}
function mhcx() {
    var param={};
    param.lineCode=$("[name=lineCode]").val();
    param.runningStatusName=$("[name=runningStatusName]").val();
    $("#lineTb").bootstrapTable("refresh",{query:param});
}
function queryParams(param){
    param.lineCode=$("[name=lineCode]").val();
    param.runningStatusName=$("[name=runningStatusName]").val();
    return param;
}
function fomStart(value,row) {
    return value==1?"启用":"停用";
}
/**
 * 线路编号下拉
 */
$(function(){
    $.getJSON(ctx+"line/search",function(arr){
        $(arr).each(function(){
            var $opt=$("<option/>");
            $opt.html(this.lineCode);
            $opt.val(this.lineCode);
            $opt.appendTo("[name=lineCode]");
        });
    });
});

function addLine(){
    $("#add").dialog("open");
}
$(function(){
    $("#add").dialog({
        title:"添加线路",
        btnName:"确定",
        btnBind:function(){
            var param = $("#add form").serialize();
            var a = $("[name=startPolecodeA]").val()
            var b = $("[name=endPolecodeA]").val()
            var start = $("[name=startPolecodeA] [value="+a+"]").html();
            var end = $("[name=endPolecodeA] [value="+b+"]").html();
            if(start==""){
                start=start;
            }
            if(end==""){
                end=end;
            }
            param+="&startPolecode="+start;
            param+="&endPolecode="+end;
             $.post(ctx+"line/addLine",param,function(msg){
                 toastr.warning("信息提示",msg);
                 $("#add").dialog("close");
                 $("#add form")[0].reset();
                 $("#lineTb").bootstrapTable("refresh");
             },'text');
        }
    });
});
function delLine(){
    var arr = $("#lineTb").bootstrapTable("getSelections");
    if(arr.length==0){
        swal({
            title: "信息提示",
            text: "请选择一项待删除！",
            type: "warning",
            showCancelButton: false,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定"
        });
        return;
    }
    swal({
        title:"确定要删除吗？",
        text:"该操作不可逆，请谨慎操作！",
        type:"warning",
        showCancelButton:true,
        confirmButtonColor:"#DD6B55",
        confirmButtonText:"确定",
        cancelButtonText:"取消",
        closeOnConfirm:false,
        closeOnCancel:false
    }).then(function(){
        $.post(ctx + "line/delLine", {lineCode: arr[0].poleInfo.lineCode}, function (msg) {
            toastr.warning(msg);
            $("#lineTb").bootstrapTable("refresh");
        })
    })
}